import store from "~/store"

function hasPermission(value, el=false){
    if(!Array.isArray(value)){
        throw new Error("无权限")
    }
    const hasAuth = value.findIndex(v=>store.state.ruleName.includes(v) != -1)
    if(el && !hasAuth){
        el.parentNode && el.parentNode.removeChild(el)
    }
    return hasAuth
}


export default{
    install(app){
        app.directive("permission", {
            mounted(el, binding) {
                hasPermission(binding.value,el)
            },
        })
    }
}